<extend name="zh_tw:Public:base" />
<block name="title">
    <title>支付方式</title>
</block>
<block name="extendHead">
    <link rel="stylesheet" type="text/css" href="/Public/dist/Home/PayPage/speedpay.css?rev=f13555acb9dbcc36f1616027bc73c312">
    <link rel="stylesheet" type="text/css" href="/Public/jslib/toastr/2.1.2/toastr.min.css?rev=e36d7ff8c89b5bb6e9db66a169d59c49">
    <style type="text/css">
    	#doc a{
    	    color: #333333;
    	}
    </style>
<block name="document">
    <div id="doc" style="margin: 0 auto;" data-symbols = "{$defaultSymbol}">
        <div class="background-F5"></div> 
        <div class="horizontal-padding bottom-divider top-divider clearfix">
            <div class="col-xs-12 col-without-padding ">
                <div class="col-xs-3 color-shallow-gray">訂單號</div>
                <div class="col-xs-9 color-deep-gray"><span class="order-number"></span></div>
            </div>
        </div>     
        <div class="horizontal-padding bottom-divider clearfix" >
            <div class="col-xs-12 col-without-padding ">
                <div class="col-xs-3 color-shallow-gray">收款方</div>
                <div class="col-xs-9 color-deep-gray"><span class="order-hotel"></span></div>
            </div>
        </div>     
        <div class="horizontal-padding bottom-divider clearfix" >
            <div class="col-xs-12 col-without-padding ">
                <div class="col-xs-3 color-shallow-gray">入住房型</div>
                <div class="col-xs-9 color-deep-gray"><span class="order-room"></span></div>
            </div>
        </div>    
        <div class="horizontal-padding bottom-divider clearfix" >
            <div class="col-xs-12 col-without-padding ">
                <div class="col-xs-3 color-shallow-gray">入住房間號</div>
                <div class="col-xs-9 color-deep-gray"><span class="order-room-num"></span></div>
            </div>
        </div>    
        <div class="horizontal-padding bottom-divider clearfix" >
            <div class="col-xs-12 col-without-padding ">
                <div class="col-xs-3 color-shallow-gray">入住時間</div>
                <div class="col-xs-9 color-deep-gray"><span class="order-checkin-date"></span>&nbsp;&nbsp;(<span class="order-night"></span>)</div>
            </div>  
        </div>    
        <div class="horizontal-padding bottom-divider clearfix" >
            <div class="col-xs-12 col-without-padding ">
                <div class="col-xs-3 color-shallow-gray">價格</div>
                <div class="col-xs-9 color-deep-gray"><span class="order-price text-accent"></span></div>
            </div>
        </div>         
        <div class="background-F5"></div> 
        <div href="/Home/PayPage/confirm?pay=1" type="button" class="pay horizontal-padding bottom-divider aliPayButton hidden">
            <div class="fixed-left-container">
                <div class="fixed-left ali-pay">支付寶</div>
                <div class="nowrap-content ali-checked"></div>
            </div> 
        </div>
        <div href="http://cz.uclbrt.com/Wechat/WechatLoginPage/auth.html?" type="button" class="pay horizontal-padding bottom-divider wechatPayButton hidden">
            <div class="fixed-left-container">
                <div class="fixed-left weixin-pay">微信支付</div>
                <div class="nowrap-content weixin-checked"></div>
            </div>   
        </div>
        <div href="/Home/PayPage/vipcardPay?pay=2" type="button" class="pay horizontal-padding bottom-divider vipcardPayButton hidden">
            <div class="fixed-left-container">
                <div class="fixed-left vipcard-pay">會員卡支付</div>
                <div class="nowrap-content vipcard-checked"></div>
            </div> 
        </div>
        <div class="horizontal-padding" style="margin-top: 16px;">
            <button disabled="disabled" id="paybtn" data-payparams='{$qrclientPayParams}' class="col-xs-12  btn-sm btn-accent btn-raised" style="line-height: 40px;height: 40px;color: #fff;font-size:16px ;" >確認支付</button>
        </div>
    </div> 
    
</block>
<block name="extendFootJs">
    <script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="/Public/jslib/toastr/2.1.2/toastr.min.js?rev=1778e466055d4a265993e979c174c338"></script>
    <script type="text/javascript" src="/Public/dist/Home/PayPage/speedpay.js?rev=8d692af1fc67167eefcfb9102b53c3d0d"></script>
    <script type="text/javascript">
        var getParams = getArgs();
        var currentHotel = getParams.hotel;
        var orderNumber = getParams.no;  
        toastr.options = {
            "newestOnTop": false,
            "timeOut": 1500,
            "extendedTimeOut": 0,
            "escapeHtml": true,
            "positionClass": "toast-bottom-center"
        };  
        if("{$error}"){
            toastr.error("{$error}");
        }
        if("{$alierror}"){
            toastr.error("{$alierror}");
        }
        // 鑰匙包微信支付回调
        var qrWechatPayCallback = function(e){
            var bookNumber = orderNumber;
            var hotelId = currentHotel;
            if (e == 1) {
                toastr.error(lang('pay.error'));
            } else if (e == 2) {
                toastr.error(lang('pay.cancel'));
            } else {
                window.location.href = "/Home/OrderPage/index?hotel=" + currentHotel + "&no=" + orderNumber;
            }
        }        
        
        $('#paybtn').on('click',function(){
           var href = $('#doc .check-pay').closest('.pay').attr('href');
           // 判断是否在鑰匙包微信支付 (不在微信浏览器)
           var isQrwechatPay = false
           if($('#doc .check-pay').closest('.pay').hasClass('wechatPayButton')){
                isQrwechatPay = true;
           }
           
           if($('.aliPayButton .ali-checked').hasClass('check-pay')){
                // 支付寶支付
                params = {
                    orderNumber: orderNumber,
                    hotel: currentHotel,
                    orderHotel: window.orderHotel,
                };
                ajaxRequest('/Home/Pay/alipay', params, 'POST', function(data) {
                    $('body').html(data.data);
                }, function(error) {
                    toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
                });
           }else if($('.vipcardPayButton .vipcard-checked').hasClass('check-pay')){
                // 會員卡支付
                window.location.href = "/Home/MemberPage/cardverify?hotel=" + currentHotel + "&no=" + orderNumber + "&orderHotel=" + window.orderHotel + "&coupon="+window.couponGetNo;
           }else{
                if($.cookie('qrclient_ali_and_wechat') != undefined && $.cookie('qrclient_ali_and_wechat') == 1){
                    // 鑰匙包微信支付方法 wechat.share()方法提供移动端调用
                    var params = {
                        hotel: currentHotel,
                        orderHotel: window.orderHotel,
                        no: orderNumber,
                        pay : 0,
                    };                    
                    ajaxRequest('/Home/PayPage/qrclientSpeedPay', params, 'POST', function(data) {
                        var payparams = data.data.qrclientPayParams; 
                        var signParams = data.data.signParams; 
                        wx.config({
                            debug: false,
                            appId: signParams.appId,
                            timestamp: signParams.timestamp,
                            nonceStr: signParams.nonceStr,
                            signature: signParams.signature,
                            jsApiList: ['chooseWXPay']
                        });
                        var qrWechatPay = function(e) {
                            wechat.share(payparams);
                        };
                        qrWechatPay();
                    }, function(error) {
                        toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
                    });
                }else{   
                    wx.config({
                        debug: false,
                        appId: "{$signParams['appId']}",
                        timestamp: "{$signParams['timestamp']}",
                        nonceStr: "{$signParams['nonceStr']}",
                        signature: "{$signParams['signature']}",
                        jsApiList: ['chooseWXPay']
                    });
                    wx.ready(function() {
                        // 確定支付按钮
                        wx.chooseWXPay({
                            timestamp: "{$payParams['timeStamp']}",
                            nonceStr: "{$payParams['nonceStr']}",
                            package: "{$payParams['package']}",
                            signType: "{$payParams['signType']}",
                            paySign: "{$payParams['paySign']}",
                            success: function(res) {
                                window.location.href = "/Home/OrderPage/index?hotel=" + currentHotel + "&no=" + orderNumber;
                            },
                            error: function() {
                                toastr.error(lang('pay.error'));
                            }
                        });
                    });                 
                }       
           }
        }); 	
    </script>
</block>
